package com.petAdoption.manager.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.petAdoption.manager.entity.Examinedeliver;
import com.petAdoption.manager.entity.Examineneck;
import com.petAdoption.manager.entity.Pet;
import com.petAdoption.manager.service.IExamineneckService;
import com.petAdoption.manager.service.IPetService;
import com.petAdoption.manager.util.Result;
import com.petAdoption.manager.vo.ExamineNeckVO;
import com.petAdoption.manager.vo.ExaminedeliverVO;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王倩茹
 * @since 2023-08-28
 */
@RestController
@RequestMapping("/examineneck")
public class ExamineneckController {
    @Resource
    private IExamineneckService examineneckService;

    @Resource
    private IPetService petService;


    @Resource
    private Result result;

    @GetMapping("/findAll")
    public Result findAll(){
        List<ExamineNeckVO> list = examineneckService.findAll();
        if(list!=null && !list.isEmpty()){
            return result.success("查找成功",list);
        }
        return result.fail("查找失败");
    }

    @PutMapping("/updateNeck")
    public Result updateNeck(@RequestBody Examineneck examineneck){
        int i  = 0;
        if (examineneck.getExamineneckStatus()==2){
            i  = examineneckService.updateStatus(examineneck);
        }else if (examineneck.getExamineneckStatus()==1){
            i  = examineneckService.updateStatus(examineneck);
            petService.update(new UpdateWrapper<Pet>().set("pet_status",2).eq("pet_id",examineneck.getExamineneckPet()));
        }

        if(i<0){
            return result.success("修改成功");
        }else {
            return result.fail("修改失败");
        }
    }

    @GetMapping("/findByStatus/{examineneckStatus}")
    public Result findByStatus(@PathVariable Integer examineneckStatus){
        List<ExamineNeckVO> list = examineneckService.findByStatus(examineneckStatus);
        if(list!=null && !list.isEmpty()){
            return result.success("查找成功",list);
        }
        return result.fail("查找失败");
    }
}
